﻿using DemoCore.Configuration;
using DemoCore.Hosts;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.ServiceModel;

namespace ClientApp
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                var configSection = ConfigurationManager.GetSection("platform") as FilterSections;
                var channelAFactory = new ChannelFactory<ISayHello>("HostEndPoint");
                List<string> address = new List<string>();
                foreach (AddressElement add in configSection.Client.HostCollection)
                {
                    address.Add(add.BaseAddress);
                }
                EndpointAddress endpointAddress = new EndpointAddress(address.FirstOrDefault() + configSection.Client.ServiceAddress);
                var channel = channelAFactory.CreateChannel(endpointAddress);

                do
                {
                    var result = channel.Hello();
                    Console.WriteLine(result);
                } while (Console.ReadLine().Length < 4);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.ReadLine();
        }
    }
}
